<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录</title>
  <style>
    label{
      display: block;
      margin:10px;
    }
  </style>
</head>
<body>
   <%- include common %>
  <%- include('head', {title:"登录"} )%>
  <h2>Login - Login - 欢迎登陆 </h2>
  <button onclick="history.go(-1)">返回上一级</button>
  <form action="/users/login" method="GET" >
    <h2>欢迎登陆</h2>
     <div>
       <label for="username">
         <input type="text" id="username" value="<%- username %>"  placeholder="请输入用户名"  name="username" >
       </label>
     </div>
     <div>
      <label for="password">
        <input type="password" id="password"  placeholder="请输入密码"  name="pass" >
      </label>
    </div>
    <div>
      <label >
        <button type="submit"> 提交登录</button>
        <button type="reset">重置</button>
        <button type="button" id="mybtn">ajax 登陆</button>
      </label>

      
    </div>
  </form>

  <%-  include("foot")  %>

  <%-  include foot %>

  <script>
    $("#mybtn").click(function(){
        $.ajax({
          url:"/users/signin",
          type:"POST",
          data:{
            username:$("#username").val(),
            pass:$("#password").val(),
          },
          success:res=>{
            console.log(res)
            const {code,msg}  =res;
            alert(msg)
            if(code==200){
            
              location.href = "/"
            }
          }
        })
    })
  </script>
</body>
</html>